<template>
	<section>
		<!--高级查询-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="query">
				<el-form-item>
					<el-input v-model="query.keyword" placeholder="关键字"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="advancedQuery">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="pageInfo.rows" highlight-current-row v-loading="listLoading" style="width: 100%;">

			<el-table-column type="index" width="60">
			</el-table-column>
			<el-table-column prop="name" label="权限名称" sortable>
			</el-table-column>
			<el-table-column prop="url" label="URL" sortable>
			</el-table-column>
			<el-table-column prop="descs" label="简介" sortable>
			</el-table-column>
			<el-table-column prop="sn" label="唯一标识" sortable>
			</el-table-column>
			<el-table-column prop="parent.name" label="父权限"sortable>
			</el-table-column>
		</el-table>


      <!--分页条-->
      <el-pagination
          style="float: right;margin: 20px"
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="query.currentPage"
          :page-sizes="pageSizes"
          :page-size="query.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pageInfo.total">
      </el-pagination>
	</section>
</template>

<script>

	export default {
		data() {
			return {
        pageInfo: {
          rows: [],
          total: 0,
        },
        pageSizes: [5, 10, 20, 50],
        //查询对象
        query: {
          //当前页,默认第一页
          currentPage: 1,
          //页面显示数据大小,默认显示5条
          pageSize: 5,
          //高级查询关键字
          keyword: ""
        },
        listLoading: false,
      }
		},
		methods: {
			handleCurrentChange(val) {
			  //改变当前显示页数
        this.query.currentPage = val;
        this.getPermissions();
			},
      handleSizeChange(val) {
			  //改变每页显示条数
        this.query.pageSize = val;
        this.getPermissions();
      },
			//获取用户列表
			getPermissions() {
				this.listLoading = false;
				this.$http.post("/permission",this.query)
        .then(result => {
          result = result.data;
          this.pageInfo = result.obj;
        })
        .catch(result =>{
          this.$message({
            message: '网络错误!',
            type: 'error'
          });
        })
			},
      advancedQuery(){
        //初始化页面
        this.query.currentPage = 1;
        //加载数据到页面
        this.getPermissions();
      }
		},
		mounted() {
			this.getPermissions();
		}
	}

</script>

<style scoped>

</style>